package com.zzu.viewmodel;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.zzu.model.bean.PackageRoute;
import com.zzu.presenter.impl.PackagePresenterImpl;
import com.zzu.utils.AppStorage;
import com.zzu.view.view.PackageQueryView;

/**
 * @description:
 * @author: bytedance
 * @date: 2021-05-18 21:57
 */
public class TransportViewModel extends ViewModel {

    private static final String TAG = TransportViewModel.class.getName();
    private MutableLiveData<String> ExpressAddress = null;
    private MutableLiveData<Integer> number = null;
    public MutableLiveData<String> getAddress() {
        if(ExpressAddress == null){
            ExpressAddress = new MutableLiveData<>();
            ExpressAddress.setValue("暂无地址信息");
        }
        return ExpressAddress;
    }

    public void saveRoute(Context context,PackageRoute packageRoute){
        Log.i(TAG,"即将存储到数据库的包裹信息："+packageRoute.toString());
        packageRoute.setTransNodeId(AppStorage.getUser().getTransNodeId());
        //获取到当前的定位，并将其写入到数据库中
        ExpressAddress.setValue(packageRoute.getAddress());
        new PackagePresenterImpl(context,new PackageQueryView<Boolean>() {
            @Override
            public void getDates(Boolean result) {
                //写入数据库成功
            }

            @Override
            public void getNoDate() {
                Toast.makeText(context,"服务器内部故障，正在抢修中",Toast.LENGTH_SHORT).show();
            }
        }).updatePackageStatus(packageRoute);
    }

}
